export function requestAuth(authName, confirmMsg) {
  return new Promise((resolve) => {
    wx.authorize({
      scope: 'scope.' + authName,
      success: (result) => {
        //{errMsg: "authorize:ok"}
        resolve({
          success: true,
          errorType: '',
          msg: result.errMsg
        })
      },
      fail: (err) => {
        uni.showModal({
          title: '提示',
          content: confirmMsg,
          success: (res) => {
            // {errMsg: "showModal:ok", cancel: false, confirm: true, content: null}
            if (res.confirm) {
              uni.openSetting({
                success: (res) => {
                  // {
                  // 	authSetting: {
                  // 		scope.userLocation: false
                  // 		scope.userLocationBackground: false
                  // 	}
                  // 	errMsg: "openSetting:ok"
                  // }
                  if (res.authSetting['scope.' + authName]) {
                    resolve({
                      success: true,
                      errorType: '',
                      msg: ''
                    })
                  } else {
                    resolve({
                      success: false,
                      errorType: 'rejectauth',
                      msg: 'rejectauth'
                    })
                  }
                }
              })
            } else {
              resolve({
                success: false,
                errorType: 'cancelmodal',
                msg: 'cancelmodal'
              })
            }
          }
        })
      }
    })
  })
}
